'use strict';

const Service = require('egg').Service;

class ListService extends Service {
    async search(username,classRoom,classNum) {

        let sql = 'select * from studentlist';

        

        if(username || classRoom || classNum){
            sql += ` where`
        }

        //and

        //拼接条件
        sql += username?` username='${username}'`:'';

        if((username && classRoom) || (username && classNum)){
            sql += ' and';
        }

        sql += classRoom?` classRoom='${classRoom}'`:'';

        if((username && classNum) || (classRoom && classNum)){
            sql += ' and';
        }

        sql += classNum?` classNum='${classNum}'`:'';

        return await this.app.mysql.query(sql);
    }
}

//select * from list where username=? and classNum=?  ,[]



module.exports = ListService;
